home *** CD-ROM | disk | FTP | other *** search
- /* -------------------------------------------
- patcher WDEF.c
-
- THINK C "Set Project Type..." settings:
- code resource, type WDEF, ID 0,
- custom header, preloaded,
- file type 'rsrc', file creator 'RSED'.
- -------------------------------------------
- */
- #include "defs.h"
-
- pascal long main( short var_code,
- WindowPeek the_window,
- short message, long param );
- Boolean No_ResEdit_danger( void );
-
- /* The one and only global variable */
- static Boolean run_needed = true;
-
- pascal long main( short var_code,
- WindowPeek the_window,
- short message, long param )
- {
- long retval;
- Handle real_WDEF_h;
- short save_resfile;
- SignedByte real_WDEF_state;
- WDEF_proc Real_WDEF;
- Ptr save_A4;
- Handle code_h;
- short res_index;
- OAPn_proc OAPn_p;
- OAPd_proc OAPd_p;
- THz save_zone;
-
- asm {
- move.L A4, save_A4
- LEA main, A4 ; for access to global
- }
-
- save_resfile = CurResFile();
- UseResFile( SysMap );
- real_WDEF_h = RGetResource( 'WDEF', 0 );
- real_WDEF_state = HGetState( real_WDEF_h );
- HLock( real_WDEF_h );
- Real_WDEF = (WDEF_proc)
- StripAddress(*real_WDEF_h);
- UseResFile( save_resfile );
-
- /* Here's where we call the real system WDEF */
- retval = Real_WDEF( var_code, the_window,
- message, param );
- HSetState( real_WDEF_h, real_WDEF_state );
-
- if (No_ResEdit_danger())
- {
- save_zone = GetZone();
- SetZone( ApplicZone() );
-
- if ( (message == wNew) && run_needed )
- {
- for (res_index = 1; ; ++res_index)
- {
- code_h = GetIndResource('OAPn', res_index);
- if (code_h == NIL)
- break;
- HLock( code_h );
- OAPn_p = (OAPn_proc) StripAddress(*code_h);
- (*OAPn_p)();
- }
- run_needed = false;
- }
-
- else if ( (message == wDraw) && // draw...
- (LoWord(param) == 0) && // all of window
- ((var_code & 3) == 0) ) // document type
- {
- for (res_index = 1; ; ++res_index)
- {
- code_h = GetIndResource('OAPd', res_index);
- if (code_h == NIL)
- break;
- HLock( code_h );
- OAPd_p = (OAPd_proc) StripAddress(*code_h);
- (*OAPd_p)( the_window );
- }
- }
-
- SetZone( save_zone );
- }
-
- asm {
- moveA.L save_A4, A4
- }
- return( retval );
- }
-
- /* -------------------------------------------
- No_ResEdit_danger If the host application
- is being edited by ResEdit
- rather than executing
- normally, we do not want this WDEF to
- install any patches.
- -------------------------------------------
- */
- Boolean No_ResEdit_danger( void )
- {
- Handle my_h;
- short my_resfile;
-
- my_resfile = -1;
- my_h = RecoverHandle( (Ptr) main );
- if (my_h != NIL)
- my_resfile = HomeResFile( my_h );
- return (my_resfile == CurApRefNum) ||
- (CurApRefNum == 2);
- }
-